package com.example.demo.Control;

import com.example.demo.Common.AjaxResult;
import com.example.demo.Entity.MessageVo;
import com.example.demo.Service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageControl {
    @Autowired
    public MessageService messageService;
    @RequestMapping("/getHistory")
    public AjaxResult getHistory(int sessionId){
        List<MessageVo> list= messageService.getHistory(sessionId);
        if(list==null){
            return  AjaxResult.fail(-1,"list为空");
        }
        Collections.reverse(list);//链表反转
        return AjaxResult.success(list);
    }
}
